package com.cn.wanxi.servlet.back.upload;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.util.DataEncoding;
import com.cn.wanxi.util.Upload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/editor/upload")
public class EditorUploadServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DataEncoding.setJsonContentType(resp);
        DataEncoding.setCharacterEncoding(req,resp);
        Upload.FileUpload(req);
        String url = DataEncoding.CastEncoding((String) req.getAttribute("img"));//保存图片的地址
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("url",url);
        System.out.println(url);
        resp.getWriter().print(jsonObject);
    }
}
